<?php

set_time_limit(0);
date_default_timezone_set('Asia/Bangkok');
include './wp-load.php';
global $titles; /*  Variable array title insterted */
$titles = array();
$cat = get_terms('category', array('hide_empty' => false));
if (count($cat)) {
    getTitlesToDay();
    $time_start = microtime(true);
    $count = 0;
    $rss = array();
    foreach ($cat as $item) {
        $temp = get_field('rss_list', 'category_' . $item->term_taxonomy_id);
        $temp_ = explode(PHP_EOL, $temp);
        $temp__ = addIDCateToRSS($temp_, $item->term_taxonomy_id);
        $rss = array_merge($rss, $temp__);
    }
    if (count($rss)) {
        foreach ($rss as $item) {
            $count += loadRSS($item);
        }
    }
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    echo '<p>Inserted ' . $count . ' news: ' . $time . ' second</p>';
}
?>